import type { PageResult } from '@/services/model/baseModel';
import type { NoticePageQuery, NoticeQueryParam, NoticeVO } from '@/services/model/noticeModel';
import { request } from '@/utils/http';

const BASE_URL = '/api/v1/notice';

/**
 * 获取公告分页列表
 */
export function getNoticePage(query: NoticePageQuery) {
  return request.Get<PageResult<NoticeVO>>(`${BASE_URL}/page`, {
    params: query,
  });
}

/**
 * 根据ID获取公告详情
 * @param id 公告ID
 */
export function getNoticeById(id: number) {
  return request.Get<NoticeVO>(`${BASE_URL}/${id}`);
}

/**
 * 新增公告
 * @param data 公告数据
 */
export function saveNotice(data: NoticeVO) {
  return request.Post<void>(BASE_URL, {
    data,
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * 更新公告
 * @param data 公告数据
 */
export function updateNotice(data: NoticeVO) {
  return request.Put<void>(BASE_URL, {
    data,
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * 批量删除公告
 * @param ids 公告ID数组
 */
export function deleteNotice(ids: number[]) {
  return request.Delete<void>(BASE_URL, {
    data: ids,
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * 导出公告
 * @param queryParams 查询参数
 */
export function exportNotice(queryParams: NoticeQueryParam) {
  return request.Get<Blob>(`${BASE_URL}/export`, {
    params: queryParams,
    responseType: 'blob',
  });
}
